package com.jar.exercise.设计模式.策略模式;

/**
 * 策略接口
 */
public interface Strategy {
	int doOperation(int o1, int o2);
}

class AddOper implements Strategy {

	@Override
	public int doOperation(int o1, int o2) {
		return o1 + o2;
	}
}

class JianOper implements Strategy {
	@Override
	public int doOperation(int o1, int o2) {
		return o1 - o2;
	}
}

class ChengOper implements Strategy {
	@Override
	public int doOperation(int o1, int o2) {
		return o1 * o2;
	}
}

class ChuOper implements Strategy {
	@Override
	public int doOperation(int o1, int o2) {
		return o1 / o2;
	}
}

class Context {
	private Strategy strategy;

	public Context(Strategy strategy) {
		this.strategy = strategy;
	}

	public Integer executeStrategy(int num1, int num2) {
		return strategy == null ? null : strategy.doOperation(num1, num2);
	}

	public static void main(String[] args) {
		Context context = new Context(new AddOper());
		System.out.println(context.executeStrategy(1, 2));
		Context context1 = new Context(new JianOper());
		System.out.println(context1.executeStrategy(1, 2));
	}
}
